var ClubDataManager = {

    //每次请求战绩 请求条数
    RequestRecordMax: 100,

    NirckNameSize: 5,   //玩家名称最长显示字符数

    FloorMin: 1,  //最小楼层
    FloorMax: 4,  //最大楼层

    //统计界面 最后选择的Tab页签  用于查看回放后 返回到指定页签
    ClubStatisticsLayerSelectTab: 0,
    //从 亲友圈战绩查看回放时 的数据
    ClubRecordData: 0,
    //桌内返回亲友圈时  指定的ClubId
    RooomReturnClubId: null,

    _clubDataMap: {}, //亲友圈数据列表 key:id  value:clubData

    _currentTableWindowRomList: [],

    //不同的玩家 不同的亲友圈数据缓存
    //因为目前是本地缓存数据，如果要切换账号的话 需要不同的账号存储不同的数据
    _playerId2ClubDataMap: {},
    getClubVersion: function () {
        return 1;
    },

    /**
     * 锁定亲友圈缓存
     * 每次存储缓存之前锁定
     * 确定缓存到当前玩家账号上
     *
     */
    lockClubDataCache: function () {
        if (!this._playerId2ClubDataMap[gameData.uid]) {
            this._playerId2ClubDataMap[gameData.uid] = {};
        } else {
        }
        this._clubDataMap = this._playerId2ClubDataMap[gameData.uid];
    },

    /**
     * 刷新俱乐部列表
     * @param clubList
     */
    refreshClubList: function (clubList) {
        this._playerId2ClubDataMap[gameData.uid] = {};
        this.lockClubDataCache();
        for (var i = 0; i < clubList.length; i++) {
            if (this._clubDataMap[clubList[i].id] == undefined) {
                this._clubDataMap[clubList[i].id] = {};
            }
            this._clubDataMap[clubList[i].id] = objectDifferenceCover(this._clubDataMap[clubList[i].id], clubList[i]);
        }
    },

    /**
     * 刷新单个亲友圈数据
     * ps:如果 已经存在id亲友圈数据。新老数据如果相同key则会覆盖。如果不同key 就会保留老数据
     * @param id
     * @param data
     */
    refreshClubData: function (id, data) {
        if (this._clubDataMap[id] != undefined) {
            this._clubDataMap[id].onLineMemberNum = data['onlineNum'];
            this._clubDataMap[id] = objectDifferenceCover(this._clubDataMap[id], data);
        }
        // if (_.isArray(id)) {
        //     var clubs = id;
        //     this.lockClubDataCache();
        //     for (var i = 0; i < clubs.length; i++) {
        //         if (this._clubDataMap[clubs[i].id] == undefined) {
        //             this._clubDataMap[clubs[i].id] = {};
        //         }
        //         this._clubDataMap[clubs[i].id] = objectDifferenceCover(this._clubDataMap[clubs[i].id], clubs[i]);
        //     }
        // } else if (this._clubDataMap[id] != undefined) {
        //     this._clubDataMap[id] = objectDifferenceCover(this._clubDataMap[id], data);
        // } else {
        //     this._clubDataMap[id] = data;
        // }
    },

    /**
     * 获取单个亲友圈数据
     * @param id
     * @returns {*}
     */
    getClubData: function (id) {
        if (this._clubDataMap[id] != undefined) {
            return this._clubDataMap[id];
        } else {
            // cc.error("当前缓存没有亲友圈id:" + id + "的数据");
        }
        return null;
    },

    /**
     * 获取所有亲友圈数据
     */
    getAllClubData: function () {
        var clubList = [];
        for (var key in this._clubDataMap) {
            clubList.push(this._clubDataMap[key]);
        }
        return clubList;
    },

    /**
     * 从亲友圈列表中 删除指定亲友圈
     * @param clubId
     * @constructor
     */
    DelectClubDataList: function (clubId) {
        for (var key in this._clubDataMap) {
            if (clubId == key) {
                delete this._clubDataMap[key];
            }
        }
    },


    /**
     * 刷新亲友圈分组数据
     * ps:覆盖式刷新
     * @param clubdId
     * @param groups
     */
    clubGroupsRefresh: function (clubId, groups) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        clubInfo.groups = groups;
        var members = clubInfo['allMember'] || [];
        var memberMap = {};
        for (var i = 0; i < groups.length; i++) {
            var group = groups[i];
            for (var j = 0; j < members.length; j++) {
                if (group['uids'] && group['uids'].indexOf(members[j].uid) >= 0) {
                    members[j].groupPos = group['pos'];
                    members[j].groupName = group['name'];
                }
                memberMap[members[j].uid] = members[j];
            }
        }
        clubInfo['allMember'] = members;
        clubInfo['memberMap'] = memberMap;
        ClubDataManager.refreshClubData(clubId, clubInfo);
        return groups;
    },

    /**
     * 获取指定亲友圈指定pos组数据
     * @param clubId
     * @param pos
     */
    getClubGroupsInfo: function (clubId, pos) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        var groups = clubInfo['groups'] || [];
        for (var i = 0; i < groups.length; i++) {
            if (groups[i].pos == pos) {
                return groups[i];
            }
        }
        return groups;
    },

    /**
     * 获取指定组的 成员数据
     * @param clubId
     * @param pos
     */
    getClubGroupMembers: function (clubId, pos) {
        var groups = this.getClubGroupsInfo(clubId, pos).uids;
        if (groups == undefined) {
            return [];
        }
        var members = [];
        var clubInfo = ClubDataManager.getClubData(clubId);
        var allMember = clubInfo['allMember'];
        for (var i = 0; i < allMember.length; i++) {
            if (groups.indexOf(allMember[i].uid) >= 0) {
                members.push(allMember[i]);
            }
        }
        return members;
    },


    /**
     * 获取亲友圈 所有成员信息
     * @param clubId
     * @returns {Array|*}
     */
    getClubMembers: function (clubId) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        if (clubInfo && clubInfo['allMember']) {
            return clubInfo['allMember'];
        }
        return [];
    },

    /**
     * 获取亲友圈 所有成员信息
     * @param clubId
     * @returns {Array|*}
     */
    getClubMemberMap: function (clubId) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        if (clubInfo && clubInfo['memberMap']) {
            return clubInfo['memberMap'];
        }
        return {};
    },

    /**
     * 获取所有成员详细信息
     * @param clubId
     */
    getClubMembersSort: function (clubId) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        var originalList = clubInfo['allMember'] || [];
        var owner_uid = clubInfo['owner_uid'];
        var ownerList = [];
        var adminOnLineList = [];
        var adminOffLineList = [];
        var memberOnLineList = [];
        var memberOffLineList = [];
        for (var i = 0; i < originalList.length; i++) {
            var userInfo = originalList[i];
            if (userInfo['uid'] == owner_uid) {
                ownerList.push(userInfo);
            } else if (userInfo.admins && !userInfo.owner) {
                if (userInfo.state == ClubDataManager.MemberState_OnLine || userInfo.state == ClubDataManager.MemberState_Room) {
                    adminOnLineList.push(userInfo);
                } else {
                    adminOffLineList.push(userInfo);
                }
            } else if (!userInfo.admins && !userInfo.owner) {
                if (userInfo.state == ClubDataManager.MemberState_OnLine || userInfo.state == ClubDataManager.MemberState_Room) {
                    memberOnLineList.push(userInfo);
                } else {
                    memberOffLineList.push(userInfo);
                }
            }
        }
        originalList = ownerList.concat(adminOnLineList).concat(adminOffLineList).concat(memberOnLineList).concat(memberOffLineList);
        return {member: originalList, onlineMemberNum: clubInfo.onLineMemberNum || 1};
    },


    /**
     * 刷新成员状态
     * @param clubId
     * @param inRoom   在房间内的成员
     * @param onLine   在线的成员
     * @param off_line 离线成员
     */
    clubMembersOnLine: function (clubId, inRoom, onLine, off_line) {
        var currentTime = new Date().getTime();
        var members = ClubDataManager.getClubMembers(clubId);
        var offLineMap = {};
        off_line = off_line || [];
        for (var i = 0; i < off_line.length; i++) {
            var info = off_line[i];
            offLineMap[info['uid']] = info['off_time'];
        }
        var memberMap = {};
        var onLineMemberNum = 0;
        for (var i = 0; i < members.length; i++) {
            var member = members[i];
            if (inRoom.indexOf(member.uid) >= 0) {
                members[i].state = ClubDataManager.MemberState_Room;
                members[i].stateTips = '游戏中';    // s  1 在线 2 游戏中  3离线
            } else if (onLine.indexOf(member.uid) >= 0) {
                members[i].state = ClubDataManager.MemberState_OnLine;
                members[i].stateTips = '在线';
            } else {
                members[i].state = ClubDataManager.MemberState_OffLine;
                members[i].stateTips = '离线';
            }

            if (onLine.indexOf(member.uid) >= 0) {
                onLineMemberNum++;
            }

            if (offLineMap[member.uid]) {
                members[i].offLineTime = offLineMap[member.uid];
                members[i].offLineTimerStr = ClubDataManager.getTimeDifferenceFormat(currentTime, member['offLineTime'] * 1000);
                members[i].state = ClubDataManager.MemberState_OffLine;
                members[i].stateTips = '离线';
            }
            memberMap[member.uid] = members[i];
        }
        var clubInfo = ClubDataManager.getClubData(clubId);
        clubInfo['onLineMemberNum'] = onLineMemberNum;
        clubInfo['allMember'] = members;
        clubInfo['memberMap'] = memberMap;
        ClubDataManager.refreshClubData(clubId, clubInfo);
        eventManager.dispatchEvent(ClubEvent.RefreshOffLineEvent);
    },

    /**
     * 获取指定成员信息
     * @param clubId
     * @param memberId
     * @returns {*}
     */
    getClubSingleMemberInfo: function (clubId, memberId) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        if (clubInfo['memberMap']) {
            return clubInfo['memberMap'][memberId];
        }
        return {};
    },

    /**
     * 刷新单个成员信息
     */
    refreshSingleMemberInfo: function (clubId, memberId, memberInfo) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        clubInfo['memberMap'][memberInfo.uid] = memberInfo;
        //刷新亲友圈缓存
        ClubDataManager.refreshClubData(clubId, clubInfo);
    },

    /**
     * 刷新亲友圈成员信息
     * ps:覆盖式刷新
     * @param clubId
     * @param members
     * @returns {*}
     */
    clubMembersRefresh: function (clubId, members) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        var allMember = [];
        var memberMap = {};
        var stateTipsArr = [0, '在线', '游戏中', '离线'];
        var partnerUids = this._getClubPartner(clubId);
        for (var i = 0; i < members.length; i++) {
            var uid = members[i].u;
            var member = {
                uid: members[i].u,      // u  代表uid
                state: members[i].s,    // s  1 在线 2 游戏中  3离线
                stateTips: stateTipsArr[members[i].s],    // s  1 在线 2 游戏中  3离线
                groupPos: members[i].gp, // 当前分组
                groupName: members[i].gn, // 当前分组名称
                name: members[i].n,     // 玩家名称
                headUrl: members[i].h,     // 玩家头像
                black: false,           //黑名单状态
                blackTips: '',          //黑名单描述
                owner: false,              //是否为群主
                admins: false,              //是否为管理员
                partner: false,             //是否是合伙人
            };
            if (clubInfo['black_list'] && clubInfo['black_list'].indexOf(uid) >= 0) {
                member.black = true;
                member.blackTips = '禁玩';
            }
            if (uid == clubInfo['owner_uid']) {
                member.owner = true;
            } else if (clubInfo['admins'] && clubInfo['admins'].indexOf(uid) >= 0) {
                member.admins = true;
            }

            if (partnerUids.indexOf(member.uid) > -1){
                member.partner = true;
            }
            allMember.push(member);
            memberMap[member.uid] = member;
        }
        clubInfo['allMember'] = allMember;
        clubInfo['memberMap'] = memberMap;
        //刷新亲友圈缓存
        ClubDataManager.refreshClubData(clubId, clubInfo);
        return clubInfo;
    },
    /**
     * 设置组的合伙人
     * @private
     */
    _getClubPartner: function(clubId){
        var clubInfo = ClubDataManager.getClubData(clubId);
        var groups = clubInfo.groups;
        if (groups == null || groups == undefined) return [];
        var retPartnerUids = [];
        for (var i = 0; i < groups.length; i++){
            if (groups[i].op_uid > 0){
                retPartnerUids.push(groups[i].op_uid);
            }
        }

        return retPartnerUids;
    },

    /**
     * 刷新亲友圈成员状态
     * @param clubId
     */
    clubMembersStateRefresh: function (clubId) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        var allMember = clubInfo['allMember'] || [];
        var memberMap = {};
        for (var i = 0; i < allMember.length; i++) {
            var uid = allMember[i].uid;
            if (clubInfo['black_list']) {
                if (clubInfo['black_list'].indexOf(uid) >= 0) {
                    allMember[i].black = true;
                    allMember[i].blackTips = '禁玩';
                } else {
                    allMember[i].black = false;
                    allMember[i].blackTips = '';
                }
            }
            allMember[i].owner = (uid == clubInfo['owner_uid']);
            if (clubInfo['admins']) {
                allMember[i].admins = (clubInfo['admins'].indexOf(uid) >= 0);
            }
            memberMap[allMember[i].uid] = allMember[i];
        }
        clubInfo['memberMap'] = memberMap;
        //刷新亲友圈缓存
        ClubDataManager.refreshClubData(clubId, clubInfo);
    },


    /**
     * 刷新指定亲友圈 牌桌信息
     * @param clubId
     * @param arr
     */
    clubListRoomRefresh: function (clubId, arr) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        var floorRoomList = {};
        for (var i = 0; i < arr.length; i++) {
            var roomInfo = arr[i];
            var option = null;
            try {
                option = JSON.parse(roomInfo.option);
            } catch (e) {
                option = roomInfo.option;
            }

            if (!floorRoomList[option.pos]) {
                floorRoomList[option.pos] = [];
            }
            floorRoomList[option.pos].push(roomInfo);
        }
        clubInfo.floorRoomList = floorRoomList;
        clubInfo.roomList = arr;
        //刷新亲友圈缓存
        ClubDataManager.refreshClubData(clubId, clubInfo);
    },

    /**
     * 获取亲友圈指定楼层房间列表
     * ps:如果楼层为null 或者 0 则获取所有房间列表
     * @param clubId
     * @param floor
     * @returns {Array}
     */
    getClubFloorRomList: function (clubId, floor) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        var floorRoomList = clubInfo.floorRoomList || {};
        var roomList = [];
        if (floorRoomList[floor]) {
            roomList = floorRoomList[floor];
        } else if (floor == null || floor == 0) {
            for (var key in floorRoomList) {
                roomList = roomList.concat(floorRoomList[key]);
            }
        }
        return roomList;
    },

    /**
     * 获取指定亲友圈玩法
     * @param clubId
     */
    getClubWanfas: function (clubId) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        var wanfasInfo = clubInfo.wanfas || [];
        wanfasInfo = wanfasInfo.sort(function (a, b) {
            return a.pos > b.pos ? -1 : 1;
        });
        return wanfasInfo;
    },
    /**
     * 获取指定亲友圈 楼层玩法信息
     * @param clubId
     * @param floor
     * @returns
     */
    getClubFloorWanfaInfo: function (clubId, floor) {
        var wanfasInfo = ClubDataManager.getClubWanfas(clubId);
        for (var i = 0; i < wanfasInfo.length; i++) {
            if (wanfasInfo[i].pos == floor) {
                return wanfasInfo[i];
            }
        }
        return wanfasInfo;
    },


    /**
     * 检测某个玩家是否是 亲友圈的管理员或者群主
     * @param clubid
     * @param uid
     * @returns {boolean}
     */
    isSelfAdministration: function (clubid, uid) {
        var clubInfo = ClubDataManager.getClubData(clubid);
        if (!clubInfo) return false;
        if (clubInfo['owner_uid'] == uid || (clubInfo['admins'] && clubInfo['admins'].indexOf(uid) >= 0)) {
            return true;
        }
        return false;
    },


    /**
     * 获取指定楼层玩法 转换成 房间牌桌列表数据
     * @param pos
     * @returns {Array}
     * @private
     */
    getWanfaFormatRoomList: function (wanfasInfo) {
        if (!_.isArray(wanfasInfo)) {
            wanfasInfo = [wanfasInfo];
        }

        var wanfaRoomList = [];
        for (var i = 0; i < wanfasInfo.length; i++) {
            var wanfaInfo = ClubDataManager.analysisWanFaInfo(JSON.parse(wanfasInfo[i].options));
            var playerMap = wanfaInfo.playerMap; //当前玩法所支持的玩家人数
            ///key 是玩家人数  value:是玩家人数对应send时的服务器字段
            for (var key in playerMap) {
                var wanfa = {};
                wanfa.maxPlayerNum = key;
                wanfa.name = ClubDataManager.getDesc2WanfaName(wanfasInfo[i]);
                wanfa.remarks = wanfasInfo[i].remarks;
                wanfa.pos = wanfasInfo[i].pos;
                wanfa.table_state = ClubTableItemType.Type_CreatRoom;
                //备份一下options数据
                wanfa.options = _.cloneDeep(wanfaInfo);

                //如果房间人数字段为数组
                //则是 PlayerCount:2 或者 maxPlayerCnt:2的玩法
                //playerMap[key]为创建房间时的字段
                if (_.isArray(playerMap[key])) {
                    wanfa.options[playerMap[key][0]] = playerMap[key][1];
                } else {
                    wanfa.options[playerMap[key]] = true;
                }
                wanfa.desc = wanfasInfo[i].desc;
                wanfaRoomList.push(wanfa);
            }
        }
        return wanfaRoomList;
    },


    /**
     * 获取格式化后的房间列表数据
     * 这里的数据格式为客户端自己单独模拟用于显示牌桌的
     * @param roomList  格式化前的房间信息
     * @param state  房间状态
     * @param pos    获取的楼层  不传为所有楼层房间
     * @private
     */
    getFormatClubRoomList: function (roomList, state, pos) {
        var returnRoomList = [];
        for (var i = 0; i < roomList.length; i++) {
            var roomInfo = roomList[i];
            var option = null;
            try {
                option = JSON.parse(roomInfo.option);
            } catch (e) {
                option = roomInfo.option;
            }
            var wanfa = {};
            wanfa.roomInfo = roomInfo;
            wanfa.name = option.name;
            wanfa.remarks = option.remarks;
            wanfa.pos = option.pos;
            wanfa.options = option;
            wanfa.desc = roomInfo.wanfa;
            wanfa.state = roomInfo.status;
            wanfa.table_state = wanfa.state;
            if (roomList[i].uids) {
                wanfa.currentPlayerNum = roomList[i].uids.length;
            } else if (roomList[i].nicknames) {
                wanfa.currentPlayerNum = roomList[i].nicknames.length;
            }

            wanfa.maxPlayerNum = roomList[i]['max_player_cnt'];
            if (wanfa.state == state) {
                returnRoomList.push(wanfa);
            } else if (wanfa.state == state) {
                returnRoomList.push(wanfa);
            }
        }
        if (returnRoomList.length == 0) return returnRoomList;
        /*
        //测试暂时保留
        var tmpData = deepCopy(returnRoomList[0]);
        function getRndInteger(min, max) {
            return Math.floor(Math.random() * (max - min + 1) ) + min;
        }

        var maxPN = getRndInteger(2, 4);
        var curPN = getRndInteger(1, maxPN);
        var timeOffset = getRndInteger(-100000, 100000);

        var tmpInData;
        for (var i = 0; i < 30; i++){
            maxPN = getRndInteger(2, 4);
            curPN = getRndInteger(1, maxPN);
            timeOffset = getRndInteger(-100000, 100000);
            tmpInData = deepCopy(tmpData);
            tmpInData['maxPlayerNum'] = maxPN;
            tmpInData['currentPlayerNum'] = curPN;
            tmpInData['roomInfo']['create_time'] += timeOffset;
            returnRoomList.push(tmpInData);
        }
        */
        returnRoomList = this.sortClubRoomListWithWait(returnRoomList);
        return returnRoomList;
    },
    /**
     * 排序等待队列
     */
    sortClubRoomListWithWait : function(tableInfoList){
        var tmpL2Arr = {
            1 : [],
            2 : [],
            3 : [],
        };

        var tableCount = tableInfoList.length;
        var tmpTableInfo;
        var tmpNum = 0;
        for (var i = 0; i < tableCount; i++){
            tmpTableInfo = tableInfoList[i];
            tmpNum = tmpTableInfo['maxPlayerNum'] - tmpTableInfo['currentPlayerNum'];
            if (tmpNum == 1 || tmpNum == 2 || tmpNum == 3) tmpL2Arr[tmpNum].push(tmpTableInfo);
        }

        for (var i = 1; i <= 3; i++){
            tmpL2Arr[i].sort(function (a, b) {
                return b['roomInfo']['create_time'] - a['roomInfo']['create_time'];
            })
        }

        var retList = [];
        var tmpLen = 0;
        for (var i =  1; i <= 3; i++){
            tmpLen = tmpL2Arr[i].length;
            for (var j = 0; j < tmpLen; j++){
                retList.push(tmpL2Arr[i][j]);
            }
        }

        return retList;
    },

    /**
     * 解析玩法信息。返回玩法支持的人数数组
     * @param wafaInfo
     * @returns {Array}  如果长度为1则为普通玩法,如果长度超过1则数组元素就是支持的玩法人数
     */
    analysisWanFaInfo: function (wafaInfo) {
        // wafaInfo = JSON.parse(wafaInfo);
        var playerMap = {};
        var allowRenshu = '';
        var isDuoRen = false;
        for (var i = 0; i < 9; i++) {
            var wanjiarenshu = 'wanjiarenshu' + i;
            if (wafaInfo[wanjiarenshu]) {
                isDuoRen = true;
                var num = i + 2;
                // if (_.isArray(wafaInfo[wanjiarenshu])) {
                //     playerMap[num] = wafaInfo[wanjiarenshu][0];
                // } else {
                //     playerMap[num] = wafaInfo[wanjiarenshu];
                // }
                playerMap[num] = wafaInfo[wanjiarenshu];
                allowRenshu += num + ',';
                delete wafaInfo[wanjiarenshu];
            }
            //后缀 i  + 2 就是玩家人数
            // 'wanjiarenshu0' -> 2
            // 'wanjiarenshu1' -> 3
            // 'wanjiarenshu2' -> 4
            // 'wanjiarenshu3' -> 5
        }
        if (!isDuoRen) {
            var renshuMap = {
                2: ['liangren', 'Liangren', 'liangrenwan', 'erren', 'liangrenSuiji'],
                3: ['sanrenwan', 'Sanrenwan', 'sanren', 'sanrenSuiji', 'sanrenGuding'],
                4: ['sirenwan', 'Sirenwan', 'siren', 'sirenGuding'],
            };
            for (var key in renshuMap) {
                var ziduans = renshuMap[key];
                for (var i = 0; i < ziduans.length; i++) {
                    var ziduan = ziduans[i];
                    if (wafaInfo[ziduan]) {
                        playerMap[key] = ziduan;
                    }
                }
            }
            if (wafaInfo['PlayerCount']) {
                var num = wafaInfo['PlayerCount'];
                playerMap[num] = ['PlayerCount', num];
            } else if (wafaInfo['maxPlayerCnt']) {
                var num = wafaInfo['maxPlayerCnt'];
                playerMap[num] = ['maxPlayerCnt', num];
            } else if (wafaInfo['Players']) {
                var num = wafaInfo['Players'];
                playerMap[num] = ['Players', num];
            } else if (wafaInfo['ClubPlayerCnt']) {
                var num = wafaInfo['ClubPlayerCnt'];
                playerMap[num] = ['ClubPlayerCnt', num];
            }
        } else {
            if (wafaInfo.siren) {
                delete wafaInfo.siren;
            }
            if (wafaInfo.liangren) {
                delete wafaInfo.liangren;
            }
            if (wafaInfo.sanrenwan) {
                delete wafaInfo.sanrenwan;
            }
            if (wafaInfo.liangrenwan) {
                delete wafaInfo.liangrenwan;
            }
            if (wafaInfo.sirenwan) {
                delete wafaInfo.sirenwan;
            }
            wafaInfo.AllowRenshu = allowRenshu;
        }
        wafaInfo.playerMap = playerMap;
        return wafaInfo;
    },


    /**
     * 根据desc获取的玩法名称
     * 有些玩法是 同一个mapId多个玩法
     * @param wanfaInfo
     * @returns {*|string}
     */
    getDesc2WanfaName: function (wanfaInfo) {
        var desc = wanfaInfo['desc'];
        if (!desc) {
            desc = JSON.parse(wanfaInfo.options)['name'];
        }
        var descList = desc.split(',');
        var wanFaName = descList[0];
        var isNum = /[0-9]/.test(wanFaName);
        if (isNum && wanFaName.indexOf('局') >= 0) {
            wanFaName = descList[1];
        }
        return wanFaName;
    },


    /**
     * 获取聊呗进群所需的url
     * @param clubId
     */
    getLiaoBeiUrl: function (clubId) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        if (clubInfo['liaobei'] && clubInfo['liaobei']['roomInfo'] && clubInfo['liaobei']['roomInfo']['room_url']) {
            return clubInfo['liaobei']['roomInfo']['room_url'];
        }
        return null;
    },

    /**
     * 检测指定 uid是否在指定亲友圈里被禁玩
     * @param clubId
     * @param targetUid
     * @returns {boolean}
     */
    getUidIsBackList: function (clubId, targetUid) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        //判断是否禁玩
        var black_list = clubInfo.black_list || [];
        if (black_list.length > 0) {
            var isfind = _.filter(black_list, function (uid) {
                return targetUid == uid;
            });
            if (isfind.length > 0) {
                return true;
            }
        }
        return false;
    },

    setClubTableWindowState: function (state) {
        this._inRoom = state;
    },

    getClubTableWindowState: function () {
        return this._inRoom || false;
    },

    /**
     * 检测uid是否为指定亲友圈定的管理员
     * @param clubId
     * @param uid
     * @returns {boolean}
     */
    getClubUidIsAdmin: function (clubId, uid) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        if (clubInfo['owner_uid'] != uid && (clubInfo['admins'] && clubInfo['admins'].indexOf(uid) >= 0)) {
            return true;
        }
        return false;
    },
    /**
     * 获得俱乐部的拥有者id
     * @param clubId
     * @returns {boolean}
     */
    getClubOwnerUid: function (clubId) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        return clubInfo['owner_uid'];
    },
    /**
     * 获得俱乐部的拥有者名字
     * @param clubId
     * @returns {boolean}
     */
    getClubOwnerName: function (clubId) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        return clubInfo['nick'];
    },

    /**
     * 听过玩法信息 得到玩法名称
     * ps:目前只有在战绩信息 获取玩法名称时 使用
     * @param wanfaInfo
     * @returns {string}
     */
    getWanfaInfo2WanfaName: function (wanfaInfo) {
        var wanfaName = '没有匹配到名称';
        //获取存储玩法名称的字段
        //目前只有字牌特殊 会把玩法名称存放在optionstring里
        if (wanfaInfo['optionstring']) {
            var obj = JSON.parse(wanfaInfo['optionstring']);
            wanfaName = obj.name || '';
        }
        if (wanfaInfo['wanfa']) {
            var strList = wanfaInfo['wanfa'].split(',');
            wanfaName = strList[0];
        }
        return wanfaName;
    },

    /**
     * 检测指定亲友圈是否打烊
     * @param clubId
     * @returns {boolean}
     */
    getClubIsShutDown: function (clubId) {
        var clubInfo = ClubDataManager.getClubData(clubId);
        var yyopen = clubInfo['openingtime'] || 'closed';
        var stime = clubInfo['start'] || '0:0';
        var etime = clubInfo['end'] || '0:0';
        var isopen = ClubDataManager.getTimeArea(stime, etime);
        return (yyopen == 'open' && !isopen);
    },

    /**
     * 获取当前包的 所有玩法的mapId 拼接成string
     */
    getAllAppWanfaMapIdStr: function () {
        var str = '';
        for (var key in club.ClubWanfaFilter) {
            if (club.ClubWanfaFilter[key].length > 0) {
                str += club.ClubWanfaFilter[key].join(',') + ',';
            }
        }
        str = str.substring(0, str.length - 1);
        return str;
    },


    setCurrentTableWindowRoomList: function (list) {
        this._currentTableWindowRomList = list;
    },

    getCurrentTableWindowRoomList: function () {
        return this._currentTableWindowRomList;
    },


    /**
     * 检测所有俱乐部列表 查看是否包含指定俱乐部Id
     * @param clubId
     */
    checkClubListHaveClubId: function (clubId) {
        var clubs = ClubDataManager.getAllClubData();
        for (var i = 0; i < clubs.length; i++) {
            if (clubs[i]['_id'] == clubId) {
                return true;
            }
        }
        return false;
    },

    /**
     * 统计界面 时间显示统一格式化
     * @param year
     * @param month
     * @param day
     * @returns {*[]}
     */
    dateFromat: function (year, month, day) {
        if (month < 10) {
            month = '0' + month;
        }
        if (day < 10) {
            day = '0' + day;
        }
        return [year, month, day];
    },


    /**
     * 检测指定是否在指定时间内
     * @param stime
     * @param etime
     * @returns {boolean}
     */
    getTimeArea: function (stime, etime) {
        var myDate = new Date();
        var nh = myDate.getHours();
        var nm = myDate.getMinutes();
        var arr1 = stime.split(':');
        var arr2 = etime.split(':');
        var sh = parseInt(arr1[0]);
        var sm = parseInt(arr1[1]);
        var eh = parseInt(arr2[0]);
        var em = parseInt(arr2[1]);
        if (sh < eh) {//非跨天
            if (nh > sh && nh < eh) {
                return true;
            } else if (nh == sh && nm >= sm) {
                return true;

            } else if (nh == eh && nm <= em) {
                return true;
            }
        } else if (sh == eh) {
            if (sm < em) {// 非跨天
                if (nh == sh && nm >= sm && nm <= em) {
                    return true;
                }
            } else if (sm > em) {//跨天
                if (nh > sh) {
                    return true;
                } else if (nh == sh && nm >= sm) {
                    return true;
                } else if (nh == sh && nm <= em) {
                    return true;
                }
            } else if (sm == em) {//完全一致认为全营业
                return true;
            }
        } else if (sh > eh) {//跨天
            if (nh == sh && nm >= sm) {
                return true;

            } else if (nh > sh) {
                return true;
            } else if (nh < eh) {
                return true;
            } else if (nh == eh && nm <= em) {
                return true;
            }
        }
        return false;
    },

    getTimeDifferenceFormat: function (tiem1, time2) {
        var timeDifference = 0;
        if (tiem1 > time2) {
            timeDifference = tiem1 - time2;
        } else {
            timeDifference = time2 - tiem1;
        }
        timeDifference = Math.ceil(timeDifference / 1000);
        // timeDifference = Math.floor(timeDifference / 1000);
        return ClubDataManager.formatSeconds(timeDifference);
    },

    formatSeconds: function (value) {
        var result = '';
        var secondTime = parseInt(value);// 秒
        var minuteTime = 0;// 分
        var hourTime = 0;// 小时
        if (secondTime >= 60) {
            //获取分钟，除以60取整数，得到整数分钟
            minuteTime = parseInt(secondTime / 60);
            //如果分钟大于60，将分钟转换成小时
            if (minuteTime > 60) {
                //获取小时，获取分钟除以60，得到整数小时
                hourTime = parseInt(minuteTime / 60);
                //获取小时后取佘的分，获取分钟除以60取佘的分
                minuteTime = parseInt(minuteTime % 60);
            }
            if (minuteTime > 0) {
                if (hourTime > 0) {
                    result = parseInt(minuteTime) + "分"
                } else {
                    result = parseInt(minuteTime) + "分钟"
                }
            }
            if (hourTime > 0) {
                result = parseInt(hourTime) + "小时" + result;
            }
        } else {
            result = '<1分钟'
        }
        return result;
    }

};
// 1 在线 2 游戏中  3离线
ClubDataManager.MemberState_OnLine = 1;
ClubDataManager.MemberState_Room = 2;
ClubDataManager.MemberState_OffLine = 3;